package com.ruoyi.common.config;

import io.minio.MinioClient;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinIOConfig {


    @Getter
    private static String minioEndpoint;
    @Getter
    private static String minioAccessKey;
    @Getter
    private static String minioSecretKey;
    @Getter
    private static String minioBucketName;


    public void setMinioEndpoint(String minioEndpoint) {
        MinIOConfig.minioEndpoint = minioEndpoint;
    }

    public void setMinioBucketName(String minioBucketName) {
        MinIOConfig.minioBucketName = minioBucketName;
    }

    public void setMinioSecretKey(String minioSecretKey) {
        MinIOConfig.minioSecretKey = minioSecretKey;
    }

    public void setMinioAccessKey(String minioAccessKey) {
        MinIOConfig.minioAccessKey = minioAccessKey;
    }


    /**
     * 创建MinIo客户端
     *
     * @return
     */

    @Bean
    public MinioClient minioClient() {

        return MinioClient.builder()
                .endpoint(MinIOConfig.getMinioEndpoint())
                .credentials(MinIOConfig.getMinioAccessKey(), MinIOConfig.getMinioSecretKey())
                .build();
    }

}
